<#include "app/task/filters/filter-for-my-payin-plan-list.ftl">

<table class="payin-plan-list" data-page="${page}" data-page-size="${pageSize}" data-count="${count}">
	<tr class="title-row">
		<th class="text-center" width="55">操作</th>
		<th class="text-center" width="45">序号</th>
		<th class="text-center">合同编号</th>
		<th class="text-center">合同名称</th>
		<th class="text-center">收款单位</th>
		<th class="text-center">收款事项</th>
		<th class="text-center">
			收款金额（元）
			<br>
			占比（%）
		</th>
		<th class="text-center">收款时间</th>
		<th class="text-center">责任人</th>
		<th class="text-center">计划变更</th>
		<th class="text-center">执行情况</th>
		<th class="text-center">备注</th>
	</tr>
	<#if data??> <#list data as p>
	<!--  -->
	<#assign url=((p.contract.mainContract)?string('contract','sub-contract'))!'contract'>
	<tr class="${((p.back)?string('text-deleted',((p.overDate)?string('text-danger',''))))}" style="cursor: pointer;" data-url="${url}" data-cid="${p.contract.id}">
		<td class="text-center">
			<#if p.back?? && !p.back>
			<div class="btn btn-danger btn-xs payin-by-plan" data-id="${p.contract.id}" data-plan-id="${p.id}">收款</div>
			</#if>
		</td>
		<td class="text-center cell-for-open">${p_index+1}</td>
		<td class="text-center cell-for-open">${p.contract.no}</td>
		<td class="text-center cell-for-open">${p.contract.name}</td>
		<td class="text-center cell-for-open">${p.moneyFrom}</td>
		<td class="text-center cell-for-open">${p.reason}</td>
		<td class="text-center cell-for-open">
			${p.total?string('currency')}
			<br>
			<small class="text-danger">${((p.total/p.contract.price)?string('#,###.##%'))!'-'}</small>
		</td>
		<td class="text-center cell-for-open">${(p.backTime?string('yyyy-MM-dd'))!'-'}</td>
		<td class="text-center cell-for-open">${p.header.name}</td>
		<td class="text-center cell-for-open">${((p.changed)?string('已变更','未变更'))!'未变更'}</td>
		<td class="text-center cell-for-open">${(p.back?string('已收款','未收款'))!'-'}</td>
		<td class="text-center cell-for-open">${p.remark}</td>
	</tr>
	</#list> </#if>
</table>

<script src="${request.contextPath}/js/suredy-datetimepicker.js"></script>
<script src="${request.contextPath}/js/suredy-list.js"></script>
<script src="${request.contextPath}/core/js/jquery.form.js"></script>
<script type="text/javascript">
	var refresh = function() {
		$.suredy.loadContent('${request.contextPath}/contract-plan/my-payin-plan-list');
	};

	$(function() {
		// 初始化时间控件
		$.suredy.datetimepicker.init();

		var doSearch = function(page, pageSize) {
			var form = $('form.filter-form');

			form.ajaxSubmit({
				dataType : 'html',
				data : {
					page : page,
					pageSize : pageSize
				},
				success : function(html, textStatus, jqXHR) {
					if (!html)
						return false;

					$('div.suredy-content').html(html);
				},
				error : function(jqXHR, textStatus, errorThrown) {
					return false;
				}
			});
		};

		$('.payin-plan-list').list({
			header : false,
			paginate : function(page, pageSize, key) {
				doSearch(page, pageSize);
			}
		});

		$('.payin-plan-list').on('click', '.cell-for-open', function() {
			var $this = $(this);
			var tr = $this.parent('tr');

			window.open('${request.contextPath}/' + tr.data('url') + '/view/' + tr.data('cid'), '_blank');
		});

		// 通过收款计划收款
		$('.payin-plan-list').on('click', '.btn.payin-by-plan', function() {
			var $this = $(this);
			var id = $this.data('id'); // 合同
			var planId = $this.data('plan-id'); // 收款计划

			$.suredy.showModal({
				showFoot : false,
				icon : 'icon-plus',
				title : '新建招标类型',
				uri : '${request.contextPath}/contract/payin-money-confirm',
				data : {
					id : id,
					planId : planId
				}
			});
						
			return false;
		});

		$('.filter-search').on('click', function() {
			doSearch(1, $('table.payin-plan-list').data('page-size'));
		});

		$('.filter-reset').on('click', function() {
			$('form.filter-form input').val('');
			$('form.filter-form option:first-child').prop('selected', true);
		});
	});
</script>
